package com.guns.server;

import com.guns.domain.Car;
import com.guns.repository.Apirepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

@Service
public class CarApiServer {

   @Autowired
    private Apirepository apirepository;

    public  Car  select(String number) {

        Car car=new Car();
        car.setNumber(number);
        Example<Car> ex=Example.of(car);
        return apirepository.findOne(ex);
    }
    public Car selectByNumber(String number){
        Car car=new Car();
        car.setNumber(number);
        car.setStatus(3);
        Example<Car> ex=Example.of(car);
        if(apirepository.findOne(ex)==null||apirepository.findOne(ex).equals("")){
            car.setStatus(1);
            Example<Car> ex2=Example.of(car);
           return apirepository.findOne(ex2);
        }
         return apirepository.findOne(ex);
    }
    public void updateByNum(int status,String number,int astatus){
        apirepository.updateByNum(status,number,astatus);
    }
}
